package com.zjun.demo.experimentaldemo.honeycomb

import android.graphics.Color
import android.util.Log
import android.view.View
import android.widget.Toast
import com.google.gson.Gson
import com.zjun.demo.experimentaldemo.R
import com.zjun.demo.experimentaldemo.base.BaseActivity
import com.zjun.demo.experimentaldemo.databinding.ActivityHoneycombBinding

/**
 * 蜂窝布局
 *
 */
class HoneycombActivity : BaseActivity<ActivityHoneycombBinding>(),
    HoneycombColorView.ColorCallback {

    val colors = mutableListOf(
        "#00FF74",
        "#1CFEF7",
        "#43FFEF",
        "#32FF82",
        "#7EFEF4",
        "#C0FFF2",
        "#FF733F",
        "#A0FF6C",
        "#71FF56",
        "#FFFFFF",
        "#FE9455",
        "#FE4C34",
        "#3F51FF",
        "#8A95FF",
        "#FEE6FE",
        "#EDDA99",
        "#FFBF20",
        "#FE2F15",
        "#6E7FFE",
        "#C3B9FE",
        "#CFACFE",
        "#FFA0CC",
        "#FF64DB",
        "#BD5FFE",
        "#BD5FFE",
        "#FE81D6",
        "#FE40DA",
        "#B139FE",
        "#8906FF",
        "#FE0EDC",)


    override fun getLayoutId(): Int = R.layout.activity_honeycomb

    override fun initialize() {
        mBinding.honeycombColorView.colorCallback = this
    }

    override fun onColorSelection(color: String) {
        Toast.makeText(this, "选择了颜色:$color", Toast.LENGTH_SHORT).show()
        mBinding.color.updateColor(Color.parseColor(color))
        mBinding.color1.updateColor(Color.parseColor(color))
    }

    override fun onClick(v: View) {
        when(v.id){

            R.id.button2->{
                mBinding.honeycombColorView.updateSelectedColor(colors[(0 until colors.size).random()])
                mBinding.color.updateColor(Color.parseColor(mBinding.honeycombColorView.getSelectedColor()!!.color))
                mBinding.color1.updateColor(Color.parseColor(mBinding.honeycombColorView.getSelectedColor()!!.color))
            }

            R.id.button3->{
                val colorInfo = mBinding.honeycombColorView.getSelectedColor()
                if(colorInfo!=null){
                    Toast.makeText(this, "选择了颜色:${colorInfo?.color}", Toast.LENGTH_SHORT).show()
                    mBinding.color.updateColor(Color.parseColor(mBinding.honeycombColorView.getSelectedColor()!!.color))
                    mBinding.color1.updateColor(Color.parseColor(mBinding.honeycombColorView.getSelectedColor()!!.color))
                }else{
                    Toast.makeText(this, "没有选中颜色", Toast.LENGTH_SHORT).show()
                }
            }

            R.id.button4->{
                mBinding.color.updateIsSelected(!mBinding.color.isHasSelected())
                mBinding.color1.updateIsSelected(!mBinding.color1.isHasSelected())
            }

            R.id.button5->{
                mBinding.honeycombColorView.updateSelectedColor(null)

                //更新选中的颜色
                //mBinding.honeycombColorView.updateStrokeColor("#FE0EDC")

                //更新选中的颜色
//                mBinding.honeycombColorView.updateStrokeColors(intArrayOf(
//                    Color.parseColor("#00FF74"),
//                    Color.parseColor("#1CFEF7"),
//                    Color.parseColor("#43FFEF"),
//                    Color.parseColor("#32FF82"),
//                    Color.parseColor("#7EFEF4"),
//                    Color.parseColor("#C0FFF2"),
//                ))
            }

        }
    }


}